package com.bqtv.sport.ui.main

import android.content.Context
import android.content.Intent
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.bqtv.sport.R
import com.bqtv.sport.adapter.ActivityCenterAdapter
import com.bqtv.sport.adapter.LiveIndexMoreAdapter
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.databinding.ActivityLiveIndexMoreBinding

class LiveIndexMoreActivity : AppActivity<ActivityLiveIndexMoreBinding>() {
    var type = 1
    lateinit var companyAdapter: ActivityCenterAdapter
    lateinit var dataAdapter: LiveIndexMoreAdapter

    companion object {
        public val INTENT_TYPE = "type"
        fun start(context: Context, type: Int) {
            val intent = Intent(context, LiveIndexMoreActivity::class.java)
            intent.putExtra(INTENT_TYPE, type)
            context.startActivity(intent)
        }
    }

    override fun getViewBinding() = ActivityLiveIndexMoreBinding.inflate(layoutInflater)

    override fun initView() {
        type=intent.getIntExtra(INTENT_TYPE,1)
        binding.rcvCompany.layoutManager = LinearLayoutManager(this)
        companyAdapter= ActivityCenterAdapter()
        binding.rcvCompany.adapter=companyAdapter

        binding.rcvData.layoutManager = LinearLayoutManager(this)
        dataAdapter= LiveIndexMoreAdapter()
        binding.rcvData.adapter=dataAdapter
    }

    override fun initData() {
        companyAdapter.submitList(arrayListOf("1","2","3"))
        dataAdapter.submitList(arrayListOf("1","2","3"))

        setType()

        initListener()
    }

    private fun setType(){
        when(type){
            1->{
                binding.tv1.text=getString(R.string.home_team)
                binding.tv2.text=getString(R.string.trend)
                binding.tv3.text=getString(R.string.away_team)
                binding.tv4.text=getString(R.string.time)
                binding.tv5.text=getString(R.string.score)
                binding.tv6.visibility=View.GONE
            }
            2->{
                binding.tv1.text=getString(R.string.home_win)
                binding.tv2.text=getString(R.string.draw)
                binding.tv3.text=getString(R.string.away_win)
                binding.tv4.text=getString(R.string.return_rate)
                binding.tv5.text=getString(R.string.time)
                binding.tv6.text=getString(R.string.score)
                binding.tv6.visibility=View.VISIBLE
            }
            3->{
                binding.tv1.text=getString(R.string.more)
                binding.tv2.text=getString(R.string.trend)
                binding.tv3.text=getString(R.string.less)
                binding.tv4.text=getString(R.string.time)
                binding.tv5.text=getString(R.string.score)
                binding.tv6.visibility=View.GONE
            }
            4->{
                binding.tv1.text=getString(R.string.more)
                binding.tv2.text=getString(R.string.trend)
                binding.tv3.text=getString(R.string.less)
                binding.tv4.text=getString(R.string.time)
                binding.tv5.text=getString(R.string.corner)
                binding.tv6.visibility=View.GONE
            }
        }
    }
    private fun initListener() {

        binding.tvHandicap.setOnClickListener(this)
        binding.tvWinLoseDraw.setOnClickListener(this)
        binding.tvTotalGoals.setOnClickListener(this)
        binding.tvCorner.setOnClickListener(this)
    }

    override fun onClick(view: View) {
        super.onClick(view)
        when (view) {
            binding.tvHandicap -> {
                setButtonClear()
                binding.tvHandicap.setTextColor(resources.getColor(R.color.white))
                binding.tvHandicap.setBackgroundResource(R.drawable.button_theme)
                type=1
                setType()
            }

            binding.tvWinLoseDraw -> {
                setButtonClear()
                binding.tvWinLoseDraw.setTextColor(resources.getColor(R.color.white))
                binding.tvWinLoseDraw.setBackgroundResource(R.drawable.button_theme)
                type=2
                setType()
            }

            binding.tvTotalGoals -> {
                setButtonClear()
                binding.tvTotalGoals.setTextColor(resources.getColor(R.color.white))
                binding.tvTotalGoals.setBackgroundResource(R.drawable.button_theme)
                type=3
                setType()
            }

            binding.tvCorner -> {
                setButtonClear()
                binding.tvCorner.setTextColor(resources.getColor(R.color.white))
                binding.tvCorner.setBackgroundResource(R.drawable.button_theme)
                type=4
                setType()
            }
        }
    }
    private fun setButtonClear() {
        binding.tvHandicap.setTextColor(resources.getColor(R.color.text_222222))
        binding.tvHandicap.setBackgroundResource(R.drawable.bg_round_ffffff)
        binding.tvWinLoseDraw.setTextColor(resources.getColor(R.color.text_222222))
        binding.tvWinLoseDraw.setBackgroundResource(R.drawable.bg_round_ffffff)
        binding.tvTotalGoals.setTextColor(resources.getColor(R.color.text_222222))
        binding.tvTotalGoals.setBackgroundResource(R.drawable.bg_round_ffffff)
        binding.tvCorner.setTextColor(resources.getColor(R.color.text_222222))
        binding.tvCorner.setBackgroundResource(R.drawable.bg_round_ffffff)
    }
}